﻿#include "CRo.h"

CRo::CRo(void) {
	this->width = 0;
	this->height = 0;
	this->img = NULL;
}

CRo::~CRo(void) {

}

void CRo::Init(CContent *content,D3DXVECTOR2 pos,string path) {
	this->img = content->LoadTexture(path.c_str());
	this->position = pos;
	this->speed = D3DXVECTOR2(5,0);
	this->height = 88;
	this->width = 82;
	this->rect.left = 0;
	this->rect.top = 0;
	this->rect.right = 82;
	this->rect.bottom = 88;
	this->center = D3DXVECTOR3(0,0,0);
}

void CRo::Update(float gameTime,bool flag) {
	// trái là false, phải là true
	if((this->position.x < (SCREEN_WIDTH - this->width)) && flag) {
		this->position += this->speed;
	} else if ((this->position.x > 0) && !flag) {
		this->position -= this->speed;
	}
}

void CRo::Update(float gameTime,int mouseX) {
	if((mouseX>(SCREEN_WIDTH-this->width)) && (mouseX < 0)) {
		this->position = D3DXVECTOR2(mouseX,0);
	} 
}

void CRo::Render(CGraphic *graphic) {
	graphic->DrawTexture(this->img,this->center,this->position,D3DCOLOR_XRGB(255,255,255));
}

void CRo::Shutdown() {
	if(this->img) {
		this->img->Release();
	}
}
